package demo1;


import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //需求：调用Person的sayHello方法

        //1.实例化person并调用sayHello方法
        /*
            优点：直接明了；
            缺点：代码写死，后期开发中如果调用的对象随着业务的改变可能发生该百年时
            这样写会导致调用方也随之修改，提高了维护成本
         */
        person p = new person();
        p.sayHello();

        //2：反射调用
        Class cls = Class.forName("demo1.person");
        person p1 = (person)cls.newInstance();
        p1.sayHello();

        //3.spring容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("demo1");
        person p2 = (person) context.getBean("person.class");
        p2.sayHello();
    }
}
